<template>
	<!-- 滚动通知 -->
	<view class="notice-bar-wrapper">

		<view class="left-icon">
			<u-icon name="volume" color="#509B07" size="44rpx"></u-icon>
		</view>
		<view class="ads-line"></view>

		<view class="l-noticBar">
			<view class="marquee">
				<view class="marquee_box" id="marquee_box" :style="{height:noticeheight}">
					<view class="marquee_list" :class="{'marquee_top':animate}">
						<view class="marquee_View" v-for="(item,index) in listCopy" :key="index"
							@click="emitClick(item)">
							<view>
								<text class="swiText" v-if="item.sclType!='6'">
									<text>{{item.info}}</text>
									<text class="main-text">【{{item.scl}}】</text>
								</text>
								<view class="flex-vc swiText" v-else>
									<view>{{item.info}}</view>
									<image :src="dm_sj" class="dm-sj-img" mode=""></image>
									<view class="dm-sj-text">七光脉轮水晶</view>
									<view>的加持</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>
<script>
	export default {
		props: {
			list: {
				type: Array,
				default: []
			},
			// 展示条数
			showNum: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				dm_sj: this.$imgWxkjUrl + '/product/dm_sj.png',
				noticeheight: '', //滚动模块高度
				animate: false, //是否滚动 
				listCopy: [...this.list]
			}
		},
		created() {
			//开始滚动
			let num = this.list.length > this.showNum ? this.showNum : this.list.length
			this.noticeheight = num * 56 + 'rpx'
			const timer = setInterval(() => {
				if (this.list.length < this.showNum) { //如果小于3条则不滚动
					clearInterval(timer)
					return
				}
				this.listCopy.push(this.listCopy[0]) //每次滚动在数组最后添加数组第一个元素 然后删除第一个
				this.animate = true
				const timer1 = setTimeout(() => {
					this.listCopy.shift()
					this.animate = false
					clearTimeout(timer1)
				}, 1000)
			}, 3500)
		},
		methods: {
			emitClick(item) {
				this.$emit('clickHandle', item)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.dm-sj-img {
		width: 56rpx;
		height: 56rpx;
	}

	.dm-sj-text {
		color: #9953EB;
		font-size: 25rpx;
		margin-right: 6rpx;
	}

	// 滚动区域
	.marquee {
		width: 100%;
		display: flex;
		/* position: absolute;
      bottom: 1rem;
      left: 0; */
	}

	.marquee_box {
		position: relative;
		width: 100%;
		overflow: hidden;
		display: flex;
	}

	.marquee_list {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.marquee_top {
		transition: all 1s;
		/* margin-top: -98rpx; */
		margin-top: -54rpx;
	}

	.marquee_View {
		width: 100%;
		display: flex;
		align-items: center;
		height: 56rpx;
	}

	// .marquee_View view {
	// 	width: 100%;
	// 	// height: 44rpx;
	// 	// display: flex;
	// 	// flex-direction: row;
	// 	/* margin: 15rpx 0 0 0; */
	// 	/* padding: 10rpx; */
	// 	box-sizing: border-box;
	// 	// align-items: center;
	// 	// justify-content: space-between;
	// 	font-size: 24rpx;
	// 	color: #fff;
	// 	/* background-color: rgba(000, 000, 000, 0.5); */
	// 	border-radius: 10rpx;

	// 	// overflow: hidden;
	// 	white-space: nowrap;
	// 	text-overflow: ellipsis;
	// 	// width: 100%;
	// }

	.swiText {
		font-size: 25rpx;
		color: #194D14;
		line-height: 56rpx;
		text-align: left;
		font-style: normal;

		max-width: 600rpx;
		// background-color: red;


		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.swiText .main-text {
		font-weight: bold;
		font-size: 25rpx;
		color: #194D14;
		line-height: 44rpx;
		text-align: left;
		font-style: normal;
	}

	.notice-bar-wrapper {
		display: flex;
		align-items: center;
		width: 720rpx;
		margin: 14rpx auto;
		padding-left: 22rpx;
		overflow: hidden;

		.ads-line {
			width: 1rpx;
			height: 44rpx;
			// border: 2rpx solid ;
			background-color: #E1E1E0;
			margin: auto 18rpx;
		}

	}
</style>